M=require("ming_node")


appid="wxce9ef487ddc74aa5"
appsecret="29108a20776cd6c19538ee93d4e66d28"


app.mapping("/open/login/scanCode",async (req,res)=>{
    console.log("本机=======>",req.url)
    //code 换 accessToken,code 只能用一次
    getTokenUrl=`https://api.weixin.qq.com/sns/oauth2/access_token?appid=${appid}&secret=${appsecret}&code=${req.params.code}&grant_type=authorization_code`
    accessTokenResult=await M.get(getTokenUrl)
    console.log("=====>accessTokenResult",accessTokenResult)
    //accessToken 换 userInfo
    userInfoUrl=`https://api.weixin.qq.com/sns/userinfo?access_token=${accessTokenResult.access_token}&openid=${accessTokenResult.openid}&lang=zh_CN`
    userInfoResult=await M.get(userInfoUrl)
    console.log("=====>userInfoResult",userInfoResult)
    //设置一下session 说明用户已经登陆
    req.session={openid:accessTokenResult.openid,userInfoResult}
    res.send(M.result(userInfoResult));
})

